package com.example.dicos.service.impl;

import com.aliyun.tea.utils.StringUtils;
import com.example.dicos.entity.WxUserRoleRelation;
import com.example.dicos.entity.dot.WxUserRoleRelationDto;
import com.example.dicos.mapper.WxUserRoleRelationMapper;
import com.example.dicos.service.WxUserRoleRelationService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
public class WxUserRoleRelationServiceImpl implements WxUserRoleRelationService {
    @Autowired
    private WxUserRoleRelationMapper wxUserRoleRelationMapper;

    @Override
    public Integer addUserRole(WxUserRoleRelationDto wxUserRoleRelationDto) throws Exception {
        WxUserRoleRelation wxUserRoleRelation=new WxUserRoleRelation();
        String[] roleId = wxUserRoleRelationDto.getRoleId();
        if (roleId.length==0){
            throw new Exception("分配角色不能为空");
        }
        String join = StringUtils.join(",", Arrays.asList(roleId));
        wxUserRoleRelation.setRoleId(join);
        BeanUtils.copyProperties(wxUserRoleRelationDto, wxUserRoleRelation);
        return wxUserRoleRelationMapper.insert(wxUserRoleRelation);
    }
}
